package com.stone.aop;

import org.aspectj.lang.annotation.Pointcut;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.GenericApplicationContext;

public class TestAop {
    @Test
    public void testAop() {
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        // 2、获取配置创建的对象
        User user = context.getBean("user", User.class);
        user.add();

    }

    /**
     * 函数式风格创建对象，交给 Spring 进行管理
     */
    @Test
    public void test1() {
        // 1、创建 GenericApplicationContext 对象
        GenericApplicationContext context = new GenericApplicationContext();

        // 2、调用 context 的方法进行对象注册
        context.refresh();
        context.registerBean("user", User.class, () -> new User());

        // 3、获取在 spring 注册的对象
        User user = (User) context.getBean("user");
        System.err.println(user);
    }
}
